package test.pcs;

import com.payment.lc.pcs.client.wrap.bo.ProductionALLAttributes;
import com.payment.lc.pcs.client.wrap.bo.ProductionAttributes;
import com.payment.lc.pcs.client.wrap.model.ZiGuanTime;
import com.payment.lc.pcs.client.wrap.service.ProductionWrapService;
import com.payment.lc.pcs.common.enums.BizType;
import com.payment.lc.pcs.common.enums.DisplayType;
import com.payment.lc.pcs.common.enums.GroupType;
import com.payment.lc.pcs.common.enums.MiProductCategory;
import com.payment.lc.pcs.common.util.DateUtil;
import com.payment.lc.pcs.service.api.DynamicDataService;
import com.payment.lc.pcs.service.api.ProductionService;
import com.payment.lc.pcs.service.api.fund.JMFundService;
import com.payment.lc.pcs.service.api.modify.InterestRateService;
import com.payment.lc.pcs.service.api.modify.PcsChannelService;
import com.payment.lc.pcs.service.domain.ListWrapper;
import com.payment.lc.pcs.service.domain.Production;
import com.payment.lc.pcs.service.domain.Provider1;
import com.payment.lc.pcs.service.request.InterestRateImportRequest;
import com.payment.lc.pcs.service.request.ProductQueryReq;
import com.payment.lc.pcs.service.response.BaseResponse;
import com.payment.lc.pcs.service.response.ProductQueryResp;
import com.payment.lc.pcs.util.DateComputeUtil;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import test.BaseTest;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created on 2016/8/8.
 */
public class Demo3PcsRevisionTest4 extends BaseTest {


    @Autowired
    JMFundService jmFundService;

    @Autowired
    ProductionWrapService productionWrapService;

    @Autowired
    InterestRateService interestRateService;

    @Autowired
    @Qualifier("dynamicDataService")
    DynamicDataService dynamicDataService;

    @Autowired
    @Qualifier("dynamicDataServiceLocal")
    DynamicDataService dynamicDataServiceLocal;

    @Autowired
    PcsChannelService pcsChannelService;

    @Autowired
    @Qualifier("productionService")
    ProductionService productionService;

    @Autowired
    @Qualifier("productionServiceLocal")
    ProductionService productionServiceLocal;

    @Test
    public void test() throws Exception {
        test3();
    }

    void test8() {
        BaseResponse resp = pcsChannelService.notifyPESellout("17120029");
        display(resp);
    }

    void test7() {
        Object provider = productionService .getProvider("SF2883");
        display(provider);
    }

    static String path = "d:/WebStormWorkspace3/mifi_pcs_v2/mock/";

    static List<String> prodCodes = Demo3PcsRevisionTest3.prodCodes;

    static {
        prodCodes.clear();
        prodCodes.add("SF2883");
    }

    void test1() {
        for (int i = 0; i < prodCodes.size(); i++) {

            productionWrapService.setProductionService(productionServiceLocal);
            String productionCode = prodCodes.get(i);
            Object obj = productionWrapService.getLastZiGuanTime(productionCode);
            String str = getJSONString(obj);
            display(str);
            writeTo(obj, path + "tmp" + i + "_0.json");


            productionWrapService.setProductionService(productionService);
            Object obj1 = productionWrapService.getLastZiGuanTime(productionCode);
            String str1 = getJSONString(obj1);
            display(str1);
            writeTo(str1, path + "tmp" + i + "_1.json");

            System.out.println(i + ":" + str.equals(str1));
        }
    }

    void test2() {
        String prodCode = "FI16022";
        Production production = productionService.getProduction(prodCode);
        ProductionAttributes attributes = productionWrapService.getProductionAttributes(production);
        display(production);
        display(attributes);
    }

    void test3() throws Exception{

        Date d1 = DateUtil.parseDateNoTime("20161128");
        Date d2 = DateUtil.parseDateNoTime("20161129");

        ListWrapper<String> peProducts = dynamicDataServiceLocal.queryPEProducts(d1, d2);
        display(peProducts);
    }
    void test5() throws Exception{

        Production production = productionService.getProduction("FI16014");
        ProductionALLAttributes productionALLAttributes = productionWrapService.getProductionALLAttributes(production);
        display(productionALLAttributes);

    }
    void test4() {
        ProductQueryReq req = new ProductQueryReq();
        req.setNameOrCode("1");
        req.setLimit(20000);

        ProductQueryResp resp = dynamicDataService.queryProducts(req);
        display(resp);
    }

    void test6() {
//        String channelProdCode = "xm_ayb005";
//        String providerCode = "HKL";

        String channelProdCode = "405";
        String providerCode = "GH";


        InterestRateImportRequest req = new InterestRateImportRequest();
        req.setChannelProdCode(channelProdCode);
        req.setProviderCode(providerCode);
        req.setYearYield(new BigDecimal(8.05));
        BaseResponse baseResponse = interestRateService.importInterestRate(req);
        display(baseResponse);
    }


}